Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn when neither reader nor admin roles are selected for a user #3337

Merged
merged 3 commits into from Jan 11, 2017

Conversation

kroepke
Copy link
Member

@kroepke kroepke commented Jan 11, 2017

disallow saving without at least one of these roles present (because lots of pages require at least the reader permissions)

fixes #2116

disallow saving without at least one of these roles present (because lots of pages require at least the reader permissions)

 fixes #2116
@kroepke kroepke added this to the 2.2.0 milestone Jan 11, 2017
@kroepke kroepke requested a review from edmundoa January 11, 2017 13:07
@edmundoa edmundoa self-assigned this Jan 11, 2017
Copy link
Contributor

@edmundoa edmundoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the mentioned issues, this works well in the tests I did on the edit user page. Unfortunately, it is still possible to not include the reader/admin roles in the create user form.

As the Input containing both usages of RolesSelect is basically the same, I would suggest adding a new component that takes care of displaying the Input and validating the roles as these changes do.

render() {
const user = this.props.user;
if (!this.state.roles) {
return <Spinner />;
}
let rolesAlert = null;
const roles = this.state.newRoles;
if (roles != null && roles.indexOf('Reader') === -1 && roles.indexOf('Admin') === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could replace roles.indexOf() with roles.includes() for better reading experience. The polyfill we use should take care of converting it if the browser does not support it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, didn't know about it!

let rolesAlert = null;
const roles = this.state.newRoles;
if (roles != null && roles.indexOf('Reader') === -1 && roles.indexOf('Admin') === -1) {
rolesAlert = <Alert bsStyle="danger" role="alert" className={EditRolesFormStyle.rolesMissingAlert}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpick: this triggers a react/wrap-multilines styling warning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@kroepke
Copy link
Member Author

kroepke commented Jan 11, 2017

I opted for a simpler approach by duplication the few lines of code, rather than passing around styling props and the validation state.

Copy link
Contributor

@edmundoa edmundoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove reader role possible but not advisible
2 participants